1 Rose Chart

Vamos a cargar el archivo de datos

path = 'hotel_reservations.csv'
hotel_reservations <- read.csv(path, row.names=NULL)
hotel_reservations_2018 <- hotel_reservations[hotel_reservations$arrival_year == 2018, ]
hotel_reservations_2018 <- hotel_reservations_2018[hotel_reservations_2018$booking_status == 'Not_Canceled', ]
frecuency_month <- sapply(1:12, function(month) {
  sum(hotel_reservations_2018$arrival_month == month)
})

print(frecuency_month)
##  [1]  990 1274 1658 1741 1650 1912 1486 1496 1606 1826 1485 1713
if (!require("ggplot2")) install.packages("ggplot2"); library(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
month_name <- factor(c("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"))
frecuencia <- c(5, 12, 8, 15, 20, 10, 6, 18, 22, 14, 9, 11)

data <- data.frame(month_name, frecuency_month)

ggplot(data, aes(x = month_name, y = frecuency_month, fill = month_name)) +
  geom_bar(stat = "identity", width = 1, color = "white") +
  coord_polar(start = 0) +
  theme_minimal() +
  labs(title = "Reservas de hoteles por mes 2018",
       x = "Meses",
       y = "Frecuencia",
       fill = "Mes")

2 Bubble Chart

Vamos a cargar el archivo de datos

path_bubble = 'world_population.csv'
population <- read.csv(path_bubble, row.names=NULL)
population$Continent <- factor(population$Continent)
if (!require("ggplot2")) install.packages("ggplot2"); library(ggplot2)
if (!require("plotly")) install.packages("plotly"); library(plotly)
## Loading required package: plotly
## Warning: package 'plotly' was built under R version 4.2.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
if (!require("viridis")) install.packages("viridis"); library(viridis)
## Loading required package: viridis
## Warning: package 'viridis' was built under R version 4.2.3
## Loading required package: viridisLite
## Warning: package 'viridisLite' was built under R version 4.2.3
plotly_chart <- ggplotly(
  ggplot(population, aes(x = X2022.Population, y = Area..km.., size = World.Population.Percentage, color = Continent,
                         text =   paste("Pais: ", Country.Territory, "<br>",
                                      "Poblacion 2022: ", X2022.Population, "<br>",
                                      "Area en km2: ", Area..km.., "<br>",
                                      "Continente: ", Continent, "<br>",
                                      "Porcentaje Poblacion Mundial: ", World.Population.Percentage))) +
    geom_point(alpha = 0.7) +
    scale_size_continuous(range = c(3, 10)) +
    scale_color_discrete(name = "Continente") +
    labs(title = "Poblacion mundial vs Area (km2)")  +
    xlab("Poblacion 2022 en Millones (M)") +
    ylab("Area en km2") + 
    scale_x_continuous(labels = scales:::label_number(scale = 1e-6)) + 
    scale_y_continuous(labels = scales::label_number()) +  
    theme_minimal(),
  tooltip = "text"
)

plotly_chart

3 Force Directed-Graph

if (!require("igraph")) install.packages("igraph"); library(igraph)
## Loading required package: igraph
## Warning: package 'igraph' was built under R version 4.2.3
## 
## Attaching package: 'igraph'
## The following object is masked from 'package:plotly':
## 
##     groups
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
if (!require("dplyr")) install.packages("dplyr"); library(dplyr)
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:igraph':
## 
##     as_data_frame, groups, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
path_graph = 'routes.csv'
routes <- read.csv(path_graph, row.names = NULL)
#routes <- head(read.csv(path_graph, row.names = NULL), 1000)

routes <- subset(routes, source.airport.id != "\\N")
routes <- subset(routes, destination.airport.id != "\\N")

routes_data <- data.frame (
  init = as.numeric(routes$source.airport.id),
  end = as.numeric(routes$destination.airport.id)
)

graph_routes <- graph.data.frame(routes_data, directed = TRUE)

plot(graph_routes, 
     main = "Grafo de Vuelos", 
     #vertex.label = V(graph_routes)$name, 
     vertex.label = NA,  
     vertex.size = 5, 
     edge.arrow.size = 0.5)